package com.im.controller;


import com.im.pojo.User;
import com.im.util.JsonResult;
import com.im.service.LoginService;
import com.im.util.Key;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController

//controller+restbody=RestController
public class LoginCtrl {
    @Autowired
    private LoginService loginService;
    @PostMapping("/login")
    public JsonResult login(@RequestBody User user, HttpSession session){
        JsonResult jr=new JsonResult(0,"msg");
        user=loginService.query(user);
        if(user!=null){
            session.setAttribute(Key.SESSION_USER,user);
            jr.setData(user);
            jr.setCode(0);
            jr.setMsg("登录成功");
        }else{
            jr.setCode(1);
            jr.setMsg("登陆失败");
        }
        return jr;
    }
}
